package com.flying.pas.config.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.annotation.Transaction;
import com.flying.common.util.Codes;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.framework.service.AbstractService;
import com.flying.pas.config.model.Category;

@Service(value="CategoryService", desc="配置分组")
public class CategoryService extends AbstractService{
	private ConfigService cs;
	
	public void setConfigService(ConfigService s) {
		this.cs = s;
	}
        
	@MethodInfo("新增")
	@DaoCreate(entity=Category.ENTITY_NAME)
	public Category create(
			@Param(value=Category.CODE, required=true,	desc="代码") String code,
			@Param(value=Category.NAME, required=false,	desc="名称") String name,
			@Param(value=Category.MODULE, required=true,	desc="模块") String module,
			@Param(value=Category.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Category.CREATE_TIME, required=false,	desc="CREATE TIME") Date create_time
		) throws Exception {
		return ModelFactory.create(Category.class, 
				Category.CREATE_TIME, new Date());
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=Category.ENTITY_NAME)
	public ActionResult update(
			@Param(value=Category.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id,
			@Param(value=Category.CODE, required=true,	desc="代码") String code,
			@Param(value=Category.NAME, required=false,	desc="名称") String name,
			@Param(value=Category.MODULE, required=true,	desc="模块") String module,
			@Param(value=Category.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Category.UPDATE_TIME, required=false,	desc="UPDATE TIME") Date update_time
		) throws Exception {
		return ModelFactory.create(ActionResult.class, 
				Category.UPDATE_TIME, new Date());
	}

	@MethodInfo("删除")
	@Transaction
	@DaoRemove(entity=Category.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Category.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id
		) throws Exception {
		this.cs.removeByCategoryId(category_id);
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Category.ENTITY_NAME, pageable=true, modelClass=Category.class)
	public QueryResult<Category> findAll(
			@Param(value=Category.MODULE, required=false,	desc="模块") String module,
			@Param(value=Category.CODE, required=false,	desc="CODE", tag = "LIKE") String code,
			@Param(value=Category.NAME, required=false,	desc="NAME", tag = "LIKE") String name,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Category.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Category findByModuleAndCode(
			@Param(value=Category.MODULE, required=true,	desc="模块") String module,
			@Param(value=Category.CODE, required=true,	desc="代码") String code
		) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Category.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Category findById(
			@Param(value=Category.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id
		) throws Exception {
		return null;
	}

}